package com.cskaoyan.mall.product.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cskaoyan.mall.common.result.Result;
import com.cskaoyan.mall.product.dto.TrademarkDTO;
import com.cskaoyan.mall.product.dto.TrademarkPageDTO;
import com.cskaoyan.mall.product.model.Trademark;
import com.cskaoyan.mall.product.query.CategoryTrademarkParam;
import com.cskaoyan.mall.product.query.TrademarkParam;
import com.cskaoyan.mall.product.service.TrademarkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author Pudding
 * @Date 2024/6/30 11:13
 */
@RestController
public class AdminTradeMarkController {

    @Autowired
    TrademarkService trademarkService;

    //1. 查看品牌列表
    // http://localhost/admin/product/baseTrademark/1/10
    @GetMapping("/admin/product/baseTrademark/{pageNo}/{pageSize}")
    public Result<TrademarkPageDTO> getTradeMarkDTOList(@PathVariable Long pageNo, @PathVariable Long pageSize) {

        //设置分页参数
        Page<Trademark> trademarkPage = new Page<>(pageNo, pageSize);
        //根据分页参数，分页查询品牌列表
        TrademarkPageDTO trademarkPageDTO = trademarkService.getPage(trademarkPage);
        return Result.ok(trademarkPageDTO);
    }


    //2. 保存品牌
    //http://localhost/admin/product/baseTrademark/save
    @PostMapping("/admin/product/baseTrademark/save")
    public Result save(@RequestBody TrademarkParam trademarkParam) {

        trademarkService.save(trademarkParam);
        return Result.ok();
    }

    //3. 删除品牌
    // http://localhost/admin/product/baseTrademark/remove/10
    @DeleteMapping("/admin/product/baseTrademark/remove/{tradeMarkId}")
    public Result deleteById(@PathVariable Long tradeMarkId) {

        trademarkService.removeById(tradeMarkId);
        return Result.ok();
    }


    //4. 查询品牌
    // http://localhost/admin/product/baseTrademark/get/17
    @GetMapping("/admin/product/baseTrademark/get/{tradeMarkId}")
    public Result<TrademarkDTO> getTradeMarkDTO(@PathVariable Long tradeMarkId) {

        TrademarkDTO trademarkDTO = trademarkService.getTrademarkByTmId(tradeMarkId);
        return Result.ok(trademarkDTO);
    }

    //5. 修改品牌
    // http://localhost/admin/product/baseTrademark/update
    @PutMapping("/admin/product/baseTrademark/update")
    public Result updateTradeMark(@RequestBody TrademarkParam trademarkParam) {

        trademarkService.updateById(trademarkParam);
        return Result.ok();
    }

}
